In [1]:
"""
General workflow for importing a new session
"""
subject = 'P01' # TODO: change this for each subject
verbose = True # change this for debugging
import matplotlib
%matplotlib inline
from deepthought.datasets.openmiir.preprocessing.pipeline import Pipeline
settings = dict(debug=False, mne_log_level='Info', sfreq=64) # optional pipeline settings
pipeline = Pipeline(subject, settings)
In [2]:
pipeline.import_and_process_metadata(verbose=verbose)
pipeline.load_raw(verbose=verbose)
In [3]:
print pipeline.raw.info
In [4]:
# switch to interactive GUI mode to scroll through data
%matplotlib tk
pipeline.plot_raw();
pass
In [5]:
# switch back to inline mode
%matplotlib inline
In [6]:
# pipeline.reset_bad_channels() # use this to reset the channel list if needed
In [4]:
# TODO: change these value manually
# If you would rather apply the bandpass filter first, continue until it is applied
# and then come back to this cell
#pipeline.mark_bad_channels(None, save_to_raw=False) # nothing to change, None will keep old values
pipeline.mark_bad_channels(['P8', 'P10', 'T8'], save_to_raw=True)
In [5]:
pipeline.print_bad_channels()
In [6]:
pipeline.interpolate_bad_channels() # Note: this will overwrite data
In [7]:
pipeline.check_trial_events()
In [8]:
pipeline.check_trial_audio_onset_merge(use_audio_onsets=True, verbose=None)
In [9]:
pipeline.merge_trial_and_audio_onsets()
In [10]:
pipeline.check_psd()
pipeline.check_psd(fmax=35)
# line noise will probably be visible @ multiples of 60Hz
In [11]:
pipeline.check_channel(0)
# quite some drift and movement in the breaks
In [12]:
pipeline.bandpass_filter()
In [16]:
%matplotlib tk
pipeline.plot_raw();
pass
In [17]:
%matplotlib inline
In [13]:
pipeline.check_channel(0)
# looks like we got rid of that drift - nice!
# what's that? eyeblinks?
In [14]:
## check PSD again - after bandpass, before down-sampling
pipeline.check_psd()
pipeline.check_psd(fmax=35)
# 60Hz is still visible
In [15]:
pipeline.generate_beat_events() # Note: this includes cue-beats !!!
pipeline.beat_epochs.average().plot();
In [16]:
pipeline.find_eog_events()
# wow - that's a lot of blinking
In [17]:
pipeline.downsample()
In [18]:
## PSD after down-sampling:
pipeline.check_psd(fmax=35)
# looks less smooth than without down-sampling
In [19]:
# check events after after resampling -> should get the same result as above
pipeline.check_resampled_trial_events(plot=True, verbose=False)
In [20]:
pipeline.compute_ica(verbose=True)
In [21]:
%matplotlib inline
pipeline.plot_ica_components() # static plot
In [22]:
pipeline.inspect_source_psd(1) # plot the PSD of an IC source to look for alpha activity
pipeline.inspect_source_psd(2)
In [23]:
pipeline.find_eog_artifact_sources(plot=True, verbose=False)
In [24]:
pipeline.auto_detect_artifact_components()
In [25]:
pipeline.select_artifact_sources(selection='auto')
In [35]:
pipeline.exclude_ica_components(selection=[0, 1, 3,11]) # TODO: adapt selection list
# use cells below to decide, which components to reject, then come back to this cell
In [34]:
pipeline.inspect_ica_component(11, [0, 700])
pipeline.inspect_source_epochs(11, mode='beats', vmax=5)
pipeline.inspect_source_epochs(11, mode='eog', vmax=5)
In [28]:
for ic in pipeline.suggested_artifact_components:
# for ic in pipeline.ica.exclude:
pipeline.inspect_ica_component(ic, [0, 700])
pipeline.inspect_source_epochs(ic, mode='beats', vmax=5)
pipeline.inspect_source_epochs(ic, mode='eog', vmax=5)
In [36]:
# enable this for interactive mode
# %matplotlib tk
# pipeline.plot_sources(mode='raw') # this may take a while
# pipeline.plot_sources(mode='beats')
pipeline.plot_sources(mode='eog');
In [37]:
# switch back to non-interactive inline mode
%matplotlib inline
In [38]:
pipeline.assess_unmixing_quality(verbose=False)
In [39]:
pipeline.save_ica('100p_64c') # save for later
In [3]:
pipeline.load_ica('100p_64c')
In [47]:
raw = pipeline.ica.apply(pipeline.raw, exclude=(pipeline.ica.exclude), copy=False)
# Note: this is no longer necessary as of mne-python version 0.10-dev
# if len(raw.info['bads']) > 0:
# raw.interpolate_bads() # interpolate bad channels afterwards as they are not processed by the ICA
%matplotlib tk
pipeline.plot_raw();
pass